package com.qyhl.party.party.study;

import android.util.Log;

import com.qyhl.party.common.PartyUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.act.Catalog;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.commonlib.entity.news.PartyBuildConfigBean;

import java.util.List;

public class PartyStudyModel implements PartyStudyContract.PartyStudyModel {
    private PartyStudyPresenter mPresenter;

    public PartyStudyModel(PartyStudyPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }


    @Override
    public void getConfig() {
        EasyHttp.get(PartyUrl.PARTY_STUDY_CATALOG)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<List<PartyBuildConfigBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取内容失败！");
                    }

                    @Override
                    public void onSuccess(List<PartyBuildConfigBean> beanList) {
                        mPresenter.setConfig(beanList);
                    }
                });
    }

    @Override
    public void getConfigInfo(String catalogId, int position) {
        EasyHttp.get(PartyUrl.PARTY_STUDY_CATALOG_INFO)
                .params("cataLogId", catalogId)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .execute(new SimpleCallBack<Catalog>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取内容失败2！");
                    }

                    @Override
                    public void onSuccess(Catalog bean) {
                        mPresenter.setInfo(bean, position);
                    }
                });
    }

    @Override
    public void getList(String InnerCode, int position) {
        EasyHttp.get(PartyUrl.PARTY_STUDY_NEWS)
                .params("InnerCode", InnerCode)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("ID", "0")
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取内容失败！");
                    }

                    @Override
                    public void onSuccess(List<NewsBean> beanList) {
                        mPresenter.setList(beanList, position);
                    }
                });
    }
}
